﻿@using MvcForum.Core.Models.Activity
@using MvcForum.Core.Utilities
@model MvcForum.Web.ViewModels.Home.AllRecentActivitiesViewModel
@{
    Layout = "~/Views/Shared/_LayoutRightSideBar.cshtml";
    ViewBag.Title = @Html.LanguageString("Activity.ActivityTitle");
    var totalCount = Convert.ToInt32(Model.TotalCount);
}
@section side
{
    @Html.Partial("_CommonSideNav")
}

<div class="mainheading">
    <div class="widgetright">
        @if (Html.Settings().EnableRSSFeeds)
        {
            <a title="@Html.LanguageString("Home.Rss")" href="@Url.Action("ActivityRss", "Home")" class="rsssubscribe">
                <i class="fa fa-rss-square orange-colour"></i>
            </a>
        }
    </div>
    <h1>@Html.Raw(ViewBag.Title)</h1>
</div>

<div class="activityholder">

    @foreach (var activity in Model.Activities)
    {
        <div class="activityentry">


            @if (activity is BadgeActivity)
            {
                var badgeActivity = activity as BadgeActivity;
                <div class="row badgeactivity">
                    <div class="activitybadge col-md-1">
                        <img src="@Url.Content(AppHelpers.ReturnBadgeUrl(badgeActivity.Badge.Image))" alt="@badgeActivity.Badge.DisplayName" />
                    </div>

                    <div class="activityinfo col-md-11">
                        <p class="activityinfotext"><a href="@Html.Raw(badgeActivity.User.NiceUrl)">@Html.Raw(badgeActivity.User.UserName)</a> @Html.LanguageString("Activity.UserAwardedBadge") @Html.Raw(badgeActivity.Badge.DisplayName) @Html.LanguageString("Activity.Badge")</p>
                        <p class="activitybadgedescription">
                            @Html.Raw(badgeActivity.Badge.Description)
                            @if (badgeActivity.Badge.AwardsPoints != null && badgeActivity.Badge.AwardsPoints > 0)
                            {
                                @(string.Format("({0} {1})", badgeActivity.Badge.AwardsPoints, Html.LanguageString("Members.Points")))
                            }
                        </p>
                        <p class="activitysubdate">
                            @DatesUi.GetPrettyDate(badgeActivity.ActivityMapped.Timestamp.ToString())
                        </p>
                    </div>
                </div>
            }
            else if (activity is MemberJoinedActivity)
            {
                var memberJoinedActivity = activity as MemberJoinedActivity;
                <div class="row memberjoinedactivity">
                    <div class="activitybadge col-md-1">
                        <img src="@memberJoinedActivity.User.MemberImage(ForumConfiguration.Instance.GravatarPostSize)" alt="@memberJoinedActivity.User.UserName" />
                    </div>

                    <div class="activityinfo col-md-11">
                        <p class="activityinfotext"><a href="@Html.Raw(memberJoinedActivity.User.NiceUrl)">@Html.Raw(memberJoinedActivity.User.UserName)</a> @Html.LanguageString("Activity.UserJoined")</p>
                        <p class="activitysubdate">
                            @DatesUi.GetPrettyDate(memberJoinedActivity.ActivityMapped.Timestamp.ToString())
                        </p>
                    </div>
                </div>
            }
            else if (activity is ProfileUpdatedActivity)
            {
                var profileUpdatedActivity = activity as ProfileUpdatedActivity;
                <div class="row profileupdatedactivity">
                    <div class="activitybadge col-md-1">
                        <img src="@profileUpdatedActivity.User.MemberImage(ForumConfiguration.Instance.GravatarPostSize)" alt="@profileUpdatedActivity.User.UserName" />
                    </div>

                    <div class="activityinfo col-md-11">
                        <p class="activityinfotext"><a href="@Html.Raw(profileUpdatedActivity.User.NiceUrl)">@Html.Raw(profileUpdatedActivity.User.UserName)</a> @Html.LanguageString("Activity.ProfileUpdated")</p>
                        <p class="activitysubdate">
                            @DatesUi.GetPrettyDate(profileUpdatedActivity.ActivityMapped.Timestamp.ToString())
                        </p>
                    </div>
                </div>
            }
            else if (activity is PostCreatedActivity)
            {
                var postCreatedActivity = activity as PostCreatedActivity;
                <div class="row postcreatedactivity">
                    <div class="activitybadge col-md-1">
                        <img src="@postCreatedActivity.Post.User.MemberImage(ForumConfiguration.Instance.GravatarPostSize)" alt="@postCreatedActivity.Post.User.UserName" />
                    </div>

                    <div class="activityinfo col-md-11">
                        <p class="activityinfotext">
                            <a href="@Html.Raw(postCreatedActivity.Post.User.NiceUrl)">@Html.Raw(postCreatedActivity.Post.User.UserName)</a> replied to <a href="@Html.Raw(postCreatedActivity.Post.Topic.NiceUrl)">@Html.Raw(postCreatedActivity.Post.Topic.Name)</a> in <a href="@Html.Raw(postCreatedActivity.Post.Topic.Category.NiceUrl)">@Html.Raw(postCreatedActivity.Post.Topic.Category.Name)</a>
                        </p>

                        <div class="activitybadgedescription">
                            @Html.Raw(StringUtils.SafePlainText(postCreatedActivity.Post.PostContent).TruncateLongString(200, true)) <a href="@Html.Raw(postCreatedActivity.Post.Topic.NiceUrl + "#comment-" + postCreatedActivity.Post.Id)">go to post</a>
                        </div>
                        <p class="activitysubdate">
                            @DatesUi.GetPrettyDate(postCreatedActivity.ActivityMapped.Timestamp.ToString())
                        </p>
                    </div>
                </div>
            }
            else if (activity is TopicCreatedActivity)
            {
                var topicCreatedActivity = activity as TopicCreatedActivity;
                <div class="row topiccreatedactivity">
                    <div class="activitybadge col-md-1">
                        <img src="@topicCreatedActivity.Topic.User.MemberImage(ForumConfiguration.Instance.GravatarPostSize)" alt="@topicCreatedActivity.Topic.User.UserName" />
                    </div>

                    <div class="activityinfo col-md-11">
                        <p class="activityinfotext">
                            <a href="@Html.Raw(topicCreatedActivity.Topic.User.NiceUrl)">@Html.Raw(topicCreatedActivity.Topic.User.UserName)</a> started a topic <a href="@Html.Raw(topicCreatedActivity.Topic.NiceUrl)">@Html.Raw(topicCreatedActivity.Topic.Name)</a> in <a href="@Html.Raw(topicCreatedActivity.Topic.Category.NiceUrl)">@Html.Raw(topicCreatedActivity.Topic.Category.Name)</a>
                        </p>

                        <div class="activitybadgedescription">
                            @Html.Raw(StringUtils.SafePlainText(topicCreatedActivity.Topic.Posts.First().PostContent).TruncateLongString(200, true)) <a href="@Html.Raw(topicCreatedActivity.Topic.NiceUrl)">go to topic</a>
                        </div>
                        <p class="activitysubdate">
                            @DatesUi.GetPrettyDate(topicCreatedActivity.ActivityMapped.Timestamp.ToString())
                        </p>
                    </div>
                </div>
            }
        </div>
    }

    @if (Model.Activities.TotalPages > 1)
    {
        @Html.Pager(Convert.ToInt32(Model.PageIndex), Html.Settings().TopicsPerPage, totalCount, null)
    }

</div>